package com.plant.action;

import java.security.MessageDigest;

public class Md {
	 public String md5calc(String data) {
	  String s = data == null ? "" : data;
	  StringBuffer buf = null;
	  try {
	   byte[] strTemp = s.getBytes();
	   MessageDigest mdTemp = MessageDigest.getInstance("MD5");
	   mdTemp.update(strTemp);
	   byte[] md = mdTemp.digest();
	   int i; 
	   buf = new StringBuffer(""); 
	   for (int offset = 0; offset < md.length; offset++) {
	   i = md[offset];
	   if(i<0) i+= 256;
	   if(i<16)
	   buf.append("0");
	   buf.append(Integer.toHexString(i));
	   }
	   return buf.toString(); 
	   
	  } catch (Exception e) {
	   return null;
	  }
	 }
	 public static String MdSecret(String data) {//MD5加密的方法
		 String s = data == null ? "" : data;
		 StringBuffer buf = null;
		 try {
			 byte[] strTemp = s.getBytes();
			 MessageDigest mdTemp = MessageDigest.getInstance("MD5");
			 mdTemp.update(strTemp);
			 byte[] md = mdTemp.digest();
			 int i; 
			 buf = new StringBuffer(""); 
			 for (int offset = 0; offset < md.length; offset++) {
				 i = md[offset];
				 if(i<0) i+= 256;
				 if(i<16)
					 buf.append("0");
				 buf.append(Integer.toHexString(i));
			 }
			 return buf.toString(); 
			 
		 } catch (Exception e) {
			 return null;
		 }
	 }

//	public static void main(String[] args) {
//		Md md=new Md();
//		System.out.println(md.md5calc("Zhiwuxiansheng*#001"));;
//	 }
}
